package com.web;

import java.util.List;

/**
 * @author Songzzz
 * @Description
 * @Date 2025/2/25 15:13
 */
public class JDBCDemo {
    public static void showStudents(){
        List<Student> list= JDBCUtils.query(Student.class,"select * from student");
        for(Student s:list){
            System.out.println(s);
        }
//        try(Connection conn=DataSourceUtils.getConnection()) {
//            PreparedStatement ps=conn.prepareStatement("select * from student");
//            ResultSet rs=ps.executeQuery();
//            while (rs.next()){
//                int id=rs.getInt("id");
//                String name=rs.getString("name");
//                int age=rs.getInt("age");
//                String gender=rs.getString("gender");
//                String cellphone=rs.getString("cellphone");
//                String address=rs.getString("address");
//                System.out.println("id:"+id+" name:"+" age: "+age+" gender:"+gender+" cellphone:"+cellphone+" address:"+address);
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//        }
    }
//实现学习搜索，输入字符，只要名字输入字符都显现出来
public static void showStudent(String sname){
 List<Student> list= JDBCUtils.query(Student.class,"select * from student where name like ?","%"+sname+"%");
    for(Student s:list){
        System.out.println(s);
    }
//    Scanner scanner = new Scanner(System.in);
//    System.out.println("请查询学生的姓名：");
//    String sname = scanner.nextLine();
//    try(Connection conn=DataSourceUtils.getConnection()) {
//        PreparedStatement ps=conn.prepareStatement("select * from student where name like ?");
//        ps.setString(1,"%"+sname+"%");
//        ResultSet rs=ps.executeQuery();
//        while (rs.next()){
//            int id=rs.getInt("id");
//            String name=rs.getString("name");
//            int age=rs.getInt("age");
//            String gender=rs.getString("gender");
//            String cellphone=rs.getString("cellphone");
//            String address=rs.getString("address");
//            System.out.println("id:"+id+" name:"+name+" age: "+age+" gender:"+gender+" cellphone:"+cellphone+" address:"+address);
//        }
//    }catch (Exception e){
//        e.printStackTrace();
//    }
}
    public static boolean login(String username,String password){
        List<User> list = JDBCUtils.query(User.class,
                "select * from t_user where username = ? and password = ?",
                username,password);
        if(list.size() > 0){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        showStudents();
//        searchStudents("三");
//        JDBCUtils.update("insert into student(name,age,gender,cellphone,address) values(?,?,?,?,?)",
//                "赵小六",18,"女","15345678111","北京");
//        if(login("zhangsan","123456")){
//            System.out.println("登录成功");
//        }else{
//            System.out.println("登录失败");
//        }
    }


}
